package com.bnz.servlet;


import com.alibaba.fastjson.JSON;
import com.bnz.pojo.Student1;
import com.bnz.service.StudentService;
import com.bnz.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/student1")
public class StudentServlet extends HttpServlet {
    private StudentService studentService;
    @Override
    public void init() throws ServletException {
        studentService = new StudentServiceImpl();
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf8");
        List<Student1> students = studentService.findAll();
        String s = JSON.toJSONString(students);
        resp.getWriter().println(s);
        resp.getWriter().flush();
    }
}
